package com.tanran.taolijin.controller;

import com.tanran.taolijin.model.TaobaoUser;
import com.tanran.taolijin.service.TaobaoUserService;
import com.tanran.taolijin.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Enzo Cotter on 2019/11/4.
 */
@Controller
public class TaobaoUserController {
    @Autowired
    private TaobaoUserService taobaoUserService;

    @GetMapping("toLogin")
    public  String toLogin(){
        return "login";
    }

    @GetMapping("toRegister")
    public  String toRegister(){
        return "register";
    }

    @GetMapping("index")
    public String index(){
        return "index";
    }

    @GetMapping("showUserInfo")
    public String showUserInfo(){
        return "userInfo";
    }

    @GetMapping("userInfo")
    public String userInfo(){
        return "userInfo";
    }

    @PostMapping("login")
    @ResponseBody
    public Result login(TaobaoUser taobaoUser, HttpSession session){
       return taobaoUserService.login(taobaoUser, session);
    }

    @PostMapping("register")
    @ResponseBody
    public Result register(TaobaoUser taobaoUser){
        return taobaoUserService.register(taobaoUser);
    }


}
